package com.usian.supplier.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.usian.supplier.bean.Supplier;
import com.usian.supplier.service.SupplierService;

@Controller
@RequestMapping("/supplier")
public class SupplierAction {
	@Autowired
	private SupplierService supplierService;
	
	@RequestMapping("/findsupplier")
	@ResponseBody
	public List<Supplier> findsupplier(Supplier supplier){
		System.out.println(supplier);
		List<Supplier> findsupplier = supplierService.findsupplier(supplier);
		System.out.println(findsupplier);
		return findsupplier;
	}
	@RequestMapping("/addsupplier")
	public String addsupplier(Supplier supplier){
		System.out.println(supplier);
		supplierService.addsupplier(supplier);
		return "redirect:/jsp/supplier/supplier.jsp";
	}
	@RequestMapping("/delsupplier")
	public String delsupplier(Integer id){
		supplierService.delsupplier(id);
		return "redirect:/jsp/supplier/supplier.jsp";
	}
	@RequestMapping("/findsupplierId")
	public String findsupplierId(Integer id ,HttpServletRequest  request){
		Supplier supplier = supplierService.findsupplierId(id);
		request.getSession().setAttribute("supplierid", supplier);
		return "redirect:/jsp/supplier/updatesupplier.jsp";
	}
	@RequestMapping("/updatesupplier")
	public String updateupplier(Supplier supplier){
		supplierService.updateupplier(supplier);
		return "redirect:/jsp/supplier/supplier.jsp";
	}
}
